import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)
if (!window.sessionStorage.getItem('token') || window.sessionStorage.getItem('token') == '') {
    localStorage.setItem("lang", "ch");
}
var userMsg = JSON.parse(window.sessionStorage.getItem('user'))
var msg = JSON.parse(window.sessionStorage.getItem('msg'))

// -----------------------------------
const firstBiMsg = sessionStorage.getItem('firstBiMsg');
const product = sessionStorage.getItem('product')
const getMoney = sessionStorage.getItem('getMoney')
const tableList = JSON.parse(sessionStorage.getItem('tableList'))
const BTCUSDT = sessionStorage.getItem('BTCUSDT')
const ETHUSDT = sessionStorage.getItem('ETHUSDT')
const LTCUSDT = sessionStorage.getItem('LTCUSDT')
const HS300USDT = sessionStorage.getItem('HS300USDT')
const IC500USDT = sessionStorage.getItem('IC500USDT')
// const mainUser = JSON.parse(sessionStorage.getItem('mainUser'))
const mainUser = sessionStorage.getItem('mainUser')


const state = {
    notices: null,
    news: null,
    carousel: null,
    // lang:null,
    keepAlive: [''],
    // 登录状态
    user: userMsg,
    msg: '',
    token: window.sessionStorage.getItem('token'),

    // -------------------
    firstBiMsg: firstBiMsg,
    product:product,
    getMoney:getMoney,
    tableList:tableList,
    BTCUSDT:BTCUSDT,
    ETHUSDT:ETHUSDT,
    LTCUSDT:LTCUSDT,
    HS300USDT:HS300USDT,
    IC500USDT:IC500USDT,
    mainUser:mainUser

}

const getters = {
    keepAlive: state => state.keepAlive
}

const mutations = {
    SET_TOKEN(state, data) {
        state.token = data
        window.sessionStorage.setItem('token', JSON.stringify(data))
    },
    SET_USER(state, data) {
        state.user = data
        window.sessionStorage.setItem('user', JSON.stringify(data))
    },
    SET_MSG(state, data) {
        state.user = data
        window.sessionStorage.setItem('msg', JSON.stringify(data))
    },
    userEmpty() {
        window.sessionStorage.removeItem('user')
    },
    setKeepAlive(state, keepAlive) {
        state.keepAlive = keepAlive
    },

    // ----------------------------------
    firstBiMsg(state,msg){
        state.firstBiMsg = msg
        sessionStorage.setItem('firstBiMsg', msg)
    },
    product(state,msg){
        state.product = msg
        sessionStorage.setItem('product', msg)
    },
    getMoney(state,msg){
        state.getMoney = msg
        sessionStorage.setItem('getMoney', msg)
    },
    tableList(state,msg){
        state.tableList = msg
        sessionStorage.setItem('tableList', msg)
    },
    BTCUSDT(state,msg){
        state.BTCUSDT = msg
        sessionStorage.setItem('BTCUSDT', msg)
    },
    ETHUSDT(state,msg){
        state.ETHUSDT = msg
        sessionStorage.setItem('ETHUSDT', msg)
    },
    LTCUSDT(state,msg){
        state.LTCUSDT = msg
        sessionStorage.setItem('LTCUSDT', msg)
    },
    HS300USDT(state,msg){
        state.HS300USDT = msg
        sessionStorage.setItem('HS300USDT', msg)
    },
    IC500USDT(state,msg){
        state.IC500USDT = msg
        sessionStorage.setItem('IC500USDT', msg)
        
    },
    mainUser(state,msg){
        state.mainUser = msg
        sessionStorage.setItem('mainUser', msg)
        
    },
}

const actions = {

}

export function createStore() {
    return new Vuex.Store({
        state,
        actions,
        mutations,
        getters,
        modules: []
    })
}